<?php

class SettingsController extends AController
{

	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('index'),
				'users'=>array('@'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}

	public function actionIndex()
	{
		
		$menu = $this->convertMenuTree(Part::model()->findByPK(1)->getNestedTree());
		
		$this->render('index', array(
			'menu'=>$menu
		));
	}
	
	private function convertMenuTree($tree, $tmp = array()){

		foreach($tree as $node){
			$c = count($tmp);
			$tmp[$c]['label'] = $node['node']->title;
			if(!empty($node['node']->url))
				$tmp[$c]['url'] = eval('return Yii::app()->createUrl('.$node['node']->url.');');
			
			if(isset($node['children']))
				$tmp[$c]['items'] = $this->convertMenuTree($node['children']);
		}
		
		return $tmp;
	}
}